declare namespace w="http://schemas.microsoft.com/office/word/2003/wordml"
declare namespace o="urn:schemas-microsoft-com:office:office"
let $book := fn:doc("/hadithopaedia/ghibah1.xml")
let $title := $book/w:wordDocument/o:DocumentProperties/o:Title
let $wordCount := $book/w:wordDocument/o:DocumentProperties/o:Words
let $characterCount := $book/w:wordDocument/o:DocumentProperties/o:Characters
let $lineCount := $book/w:wordDocument/o:DocumentProperties/o:Lines
let $paraCount := $book/w:wordDocument/o:DocumentProperties/o:Paragraphs
let $paragraphs := $book//w:t

return 
<hadith>
 <header>
 { $title,
 $wordCount,
 $characterCount,
 $lineCount,
 $paraCount }
 </header>
 <body>
  {
   for $para in $paragraphs
   return 
    if ( matches($para, "^[ \t]?$") ) then
     ()
    else if(matches($para, "\[.*\]")) then 
       <page>{ replace(string(normalize-space($para)),"\[(.*)\]","$1")}</page>
    else 
       <paragraph>{ string(normalize-space($para)) }</paragraph>
  }
 </body>
</hadith>


